import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 客户信息 */
export interface customer {
  id: number // ID
  username?: string // 姓名
  sex?: number // 用户性别
  age?: number // 年龄
  quota?: number // 贷款额度
  mobile?: string // 手机号码
  followUp?: number // 跟进人
  followUpName?: string // 跟进人
  followUpStatus?: number // 跟进状态
  remark?: string // 客户条件备注
  followUpFrequency?: number // 跟进次数
  source?: number // 来源
  starRating?: number // 客户星级
  realestate?: number // 房产
  housingProvidentFund?: number // 公积金
  socialinsurance?: number // 社保
  customerType?: number // 客户类型
  followTime?: string | Dayjs // 跟进时间
}

// 客户 API
export const customerApi = {
  // 查询客户分页
  getcustomerPage: async (params: any) => {
    return await request.get({ url: `/system/customer/page`, params })
  },

  // 查询客户详情
  getcustomer: async (id: number) => {
    return await request.get({ url: `/system/customer/get?id=` + id })
  },

  // 新增客户
  createcustomer: async (data: customer) => {
    return await request.post({ url: `/system/customer/create`, data })
  },

  // 修改客户
  updatecustomer: async (data: customer) => {
    return await request.put({ url: `/system/customer/update`, data })
  },

  // 删除客户
  deletecustomer: async (id: number) => {
    return await request.delete({ url: `/system/customer/delete?id=` + id })
  },

  /** 批量删除客户 */
  deletecustomerList: async (ids: number[]) => {
    return await request.delete({ url: `/system/customer/delete-list?ids=${ids.join(',')}` })
  },

  importTemplate: async () => {
    return await request.download({ url: '/system/customer/get-import-template' })
  },

  // 导入客户 Excel
  handleImport: async (formData) => {
    return await request.upload({ url: `/system/customer/import`, data: formData })
  },

  // 导出客户 Excel
  exportcustomer: async (params) => {
    return await request.download({ url: `/system/customer/export-excel`, params })
  },

  /** 分配 */
  assign: async (data) => {
    return await request.post({ url: `/system/customer/assign-customers`, data })
  },

  /** 领取 */
  take: async (data) => {
    return await request.post({ url: `/system/customer/claim-customers`, data })
  },

  /** 移入公海 */
  movingIntoOpensea: async (data) => {
    return await request.post({ url: `/system/customer/moving-into-opensea`, data })
  },
  
  /** 移入我的客户 */
  movingIntoMyCustomer: async (data) => {
    return await request.post({ url: `/system/customer/moving-into-myCustomer`, data })
  },

  /** 移入重要客户 */
  movingIntoImportant: async (data) => {
    return await request.post({ url: `/system/customer/moving-into-important`, data })
  },

  /** 移出重要客户 */
  movingOutImportant: async (data) => {
    return await request.post({ url: `/system/customer/moving-out-important`, data })
  },

  /** 获取跟进历史 */
  getRemarkHistory: async (params) => {
    return await request.get({ url: `/system/follow/page`, params })
  },

  /** 跟进人列表 */
  getFollowUpList: async (params) => {
    return await request.get({ url: '/system/user/getList', params });
  },

  /** 部门内用户 */
  getListByDeptId: async (params) => {
    return await request.get({ url: '/system/user/getListByDeptId', params });
  },

  /** 从统计页进入类似我的客户 */
  countGetUser: async (params) => {
    return await request.get({ url: '/system/customer/countGetUser', params });
  },

  getCountInfo: async(params) => {
    return await request.get({ url: '/system/customer/getInfomation', params });
  },

  getCountUserDetailInfo: async(params) => {
    return await request.get({ url: '/system/customer/getUserInfomation', params });
  },

  /** 新客户列表 */
  getNewCustomer: async () => {
    return await request.get({ url: '/system/customer/getNewCustomer' });
  },
}
